package com.github.kotvertolet.youtubejextractor.models;



import com.github.kotvertolet.youtubejextractor.models.newModels.AdaptiveFormatsItem;
import com.github.kotvertolet.youtubejextractor.models.youtube.videoData.StreamingData;
import ohos.utils.Parcel;
import ohos.utils.Sequenceable;

public class AdaptiveAudioStream extends StreamItem implements Sequenceable {


    private int audioChannels;
    private int audioSampleRate;

    public static final Sequenceable.Producer<AdaptiveAudioStream> CREATOR = new Producer<AdaptiveAudioStream>() {
        @Override
        public AdaptiveAudioStream createFromParcel(Parcel parcel) {
            // Initialize an instance first, then do customized unmarshlling.
            AdaptiveAudioStream adaptiveAudioStream = new AdaptiveAudioStream();
            adaptiveAudioStream.unmarshalling(parcel);
            return adaptiveAudioStream;
        }
    };


    public AdaptiveAudioStream(){

    }

    public AdaptiveAudioStream(String extension, String codec, int bitrate, int iTag, String url,
                               int audioChannels, int audioSampleRate, int averageBitrate, int approxDurationMs) {
        super(extension, codec, bitrate, iTag, url, averageBitrate, approxDurationMs);
        this.audioChannels = audioChannels;
        this.audioSampleRate = audioSampleRate;
    }

    public AdaptiveAudioStream(AdaptiveFormatsItem adaptiveStream) {
        super(adaptiveStream);
        audioChannels = adaptiveStream.getAudioChannels();
        audioSampleRate = Integer.valueOf(adaptiveStream.getAudioSampleRate());
        //url = adaptiveStream.getCipher().getUrl() + "&" + adaptiveStream.getCipher().getSp() + adaptiveStream.getCipher().getS();
    }

    public int getAudioChannels() {
        return audioChannels;
    }

    public void setAudioChannels(int audioChannels) {
        this.audioChannels = audioChannels;
    }

    public int getAudioSampleRate() {
        return audioSampleRate;
    }

    public void setAudioSampleRate(int audioSampleRate) {
        this.audioSampleRate = audioSampleRate;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        if (!super.equals(o)) return false;

        AdaptiveAudioStream that = (AdaptiveAudioStream) o;

        if (audioChannels != that.audioChannels) return false;
        return audioSampleRate == that.audioSampleRate;
    }

    @Override
    public int hashCode() {
        int result = super.hashCode();
        result = 31 * result + audioChannels;
        result = 31 * result + audioSampleRate;
        return result;
    }

    @Override
    public boolean marshalling(Parcel parcel) {
        parcel.writeInt(this.audioChannels);
        parcel.writeInt(this.audioSampleRate);
        return true;
    }

    @Override
    public boolean unmarshalling(Parcel parcel) {
        this.audioChannels = parcel.readInt();
        this.audioSampleRate = parcel.readInt();
        return true;
    }
}